package com.ruoyi.apis.vo;

import com.ruoyi.apis.entity.BannerEntity;
import com.ruoyi.common.utils.ServletUtils;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author Choi
 * @Date 2021/7/19
 */

@Setter
@Getter
public class BannerVO {
    private Long id;
    private String title;
    private String bgimage;
    private String image;
    private String url;
    private String description;

    public BannerVO(BannerEntity banner) {
        BeanUtils.copyProperties(banner, this);
//        HttpServletRequest request = ServletUtils.getRequest();
//        String domain = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
//        this.setImage(banner.getImage() != null ? domain + banner.getImage() : "");
//        this.setBgimage(banner.getBgimage() != null ? domain + banner.getBgimage() : "");

    }

    public static List<BannerVO> getBannerList(List<BannerEntity> banners) {
        return banners.stream()
                .map(BannerVO::new)
                .collect(Collectors.toList());
    }
}
